import os

import chardet

from config import BASC


class RecoverData():
    def __init__(self):
        self.path=f"{BASC}/data/TempFrameData.txt"
        # path = f"{BASC}/data/TempFrameData.txt"

    def write_file_from_get_frame(self,textframelist):
        # textframelist=[]
        str_tol=None
        for uu in textframelist:
            strtemp=uu.get("1.0", "end").replace("\n", "")
            if str_tol is None:
                str_tol=f"{strtemp}\n"
            else:
                str_tol =f"{str_tol}{strtemp}\n"

        # tframe2 = fr2.get("1.0", "end").replace("\n", "")
        # tframe3 = fr3.get("1.0", "end").replace("\n", "")
        # str_tol = f"{tframe1}\n{tframe2}\n{tframe3}"

        print(f'写入文件')


        fo = open(self.path, "w+", encoding='utf-8')
        fo.write(str_tol)
        fo.close()
    # 每个textframe的删除载入数据
    def input_temp_data(self, textframe, data):
        textframe.delete('1.0', "end")
        textframe.insert('insert', f'{data}')

    def get_code(self, filepath):
        with open(filepath, 'rb') as f:
            return chardet.detect(f.read())['encoding']

    # 顺序读取
    def read_content_order22a(self, filename):

        fk3 = open(filename, "r", encoding=self.get_code(filename))
        grafk = fk3.readlines()
        fk3.close()

        # print_info(f'开头的处理数组，排序，去掉重复值这些')
        # grafk=no_repeat_list(grafk)

        aaby = []
        # 去掉换行符
        # print(f'开头的去掉换行符')
        for ssij in grafk:
            ssij = str(ssij).replace("\n", "")
            # ssij = str(ssij).replace(" ", "")
            # ssij = str(ssij).replace("　", "")
            if len(ssij) > 0:
                aaby.append(ssij)

        # aaby=no_repeat_list(aaby)
        return aaby


    def write_data(self,listoo):
        if os.path.exists(self.path):
            templist = self.read_content_order22a(self.path)
            # print(templist)
            if len(templist) > 0:
                for mm in range(len(templist)):
                    self.input_temp_data(listoo[mm], templist[mm])


class RecoverData2(RecoverData):
    #继承，有原来的，super.method
    # 重写，自己重新写一个一样的，覆盖
    #扩展
    def __init__(self):
        super(RecoverData2, self).__init__()
        self.path = f"{BASC}/data/TempFrameData2.txt"


class RecoverData3(RecoverData):
    # 继承，有原来的，super.method
    # 重写，自己重新写一个一样的，覆盖
    # 扩展
    def __init__(self):
        super(RecoverData3, self).__init__()
        self.path = f"{BASC}/data/TempFrameData3.txt"



#只筛选视频图像做时间流文件的
class RecoverData4(RecoverData):
    # 继承，有原来的，super.method
    # 重写，自己重新写一个一样的，覆盖
    # 扩展
    def __init__(self):
        super(RecoverData4, self).__init__()
        self.path = f"{BASC}/data/TempFrameData4.txt"

if __name__ == '__main__':

    pass